package pl.edu.pw.polygen.db.entieties;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "PROJECT")
public class Project {

	private Long id;
	private String name;
	private String description;
	private Date lastModification;
	private User user;
	private List<PolyFile> files = new ArrayList<PolyFile>();

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "projects_seq")
	@SequenceGenerator(name = "projects_seq", sequenceName = "projects_seq")
	@Column(name = "PROJECT_ID")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "NAME", nullable = false, length = 256)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "LAST_MODIFICATION", nullable = false)
	public Date getLastModification() {
		return lastModification;
	}

	public void setLastModification(Date lastModification) {
		this.lastModification = lastModification;
	}

	@ManyToOne()
	@JoinColumn(name="USER_ID")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "DESCRIPTION", nullable = true)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@OneToMany(targetEntity=PolyFile.class, mappedBy="project",cascade = CascadeType.ALL, fetch=FetchType.EAGER)
//	@JoinTable(name="FILES", joinColumns=@JoinColumn(name="PROJECT_ID"), inverseJoinColumns=@JoinColumn(name="FILE_ID"))
	public List<PolyFile> getFiles() {
		return files;
	}

	public void setFiles(List<PolyFile> files) {
		this.files = files;
	}
	
	
	

}
